package tt.dz.biz.service.channel;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import tt.dz.biz.dao.paymentgateway.PayChannelDAO;
import tt.dz.common.BusinessException;
import tt.dz.common.LogUtil;
import tt.dz.vo.PayChannelVO;

@Service("payChannelService")
public class PayChannelService
{
  @Resource(name="payChannelDAO")
  PayChannelDAO payChannelDAO;
  
  public List<PayChannelVO> listAllPayChannel()
  {
    List<PayChannelVO> payChannelList = null;
    try
    {
      payChannelList = this.payChannelDAO.listAllPayChannel();
    }
    catch (Exception e)
    {
      LogUtil.error("查询所有支付渠道异常", e);
      payChannelList = new ArrayList();
    }
    return payChannelList;
  }
  
  public boolean insertPayChannel(PayChannelVO payChannelVO)
  {
    boolean excuteFlag = false;
    try
    {
      int i = this.payChannelDAO.insertPayChannel(payChannelVO);
      excuteFlag = i > 0;
    }
    catch (Exception e)
    {
      LogUtil.error("插入支付渠道异常--入参：" + payChannelVO.toString(), e);
    }
    return excuteFlag;
  }
  
  public boolean updatePayChannel(PayChannelVO payChannelVO)
  {
    boolean excuteFlag = false;
    try
    {
      int i = this.payChannelDAO.updatePayChannel(payChannelVO);
      excuteFlag = i > 0;
    }
    catch (Exception e)
    {
      LogUtil.error("更新支付渠道异常--入参：" + payChannelVO.toString(), e);
    }
    return excuteFlag;
  }
  
  public PayChannelVO queryChannelByCode(String channelCode)
    throws Exception
  {
    try
    {
      if (StringUtils.isBlank(channelCode)) {
        throw new BusinessException("渠道号码不能为空");
      }
      return this.payChannelDAO.queryChannelByCode(channelCode);
    }
    catch (Exception e)
    {
      LogUtil.error("通过渠道号码查询渠道异常，参数为：" + channelCode);
      throw e;
    }
  }
  
  public List<PayChannelVO> queryChannelListByName(String name)
    throws Exception
  {
    try
    {
      return this.payChannelDAO.queryChannelListByName(name);
    }
    catch (Exception e)
    {
      LogUtil.error("通过渠道名查询渠道信息异常，参数为：name=" + name);
      throw e;
    }
  }
}
